<?php
/**
 * 更新记录：
 * 	2022-05-16 新增FastDFS.id
 */
require '../../vendor/autoload.php';

use utils\ConfigReader;
use utils\HttpHeader;
use utils\PathTool;
use utils\SysTool;
use utils\WebWriter;
use utils\StringTool;

$head = new HttpHeader();

$id          = $head->param("id");
$blockIndex  = $head->param("blockIndex");
$blockOffset = $head->param("blockOffset");
$blockSize   = $head->param("blockSize");
$pathSvr     = $head->param("pathSvr");
$fastdfs_id  = $head->param("fastdfs_id");
$minio_id    = $head->param("minio_id");
$pathSvr     = PathTool::urldecode_path($pathSvr);

if ( empty($id) 
	|| empty($blockIndex)
	|| strlen($blockOffset) < 1
	|| empty($blockSize)
	|| empty($pathSvr) ) 
{
	header('HTTP/1.1 500 param null');
	return;
}

header("Cache-Control: public");
header("Content-Type: application/octet-stream");
header("Content-Length: $blockSize");

//windows系统中需要将中文转换为gb2312
$sys = new SysTool();
$pathSvr = $sys->to_gbk($pathSvr);

if( StringTool::iequals(ConfigReader::storageType(),"FastDFS")) $pathSvr = $fastdfs_id;
if(StringTool::iequals(ConfigReader::storageType(), "Minio")) $pathSvr = $minio_id;
$ww = new WebWriter();
$ww->write($pathSvr,$blockOffset,$blockSize);
?>